package com.test.group6.service.Ipml;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.test.group6.domain.EnterpriseInformation;
import com.test.group6.mapper.AddEnterpriseMapper;
import com.test.group6.service.AddEnterpriseService;
import com.test.group6.util.CreateId;
import com.test.group6.util.DateUtil;

@Service
public class AddEnterpriseServiceImpl implements AddEnterpriseService {

	private final String IDTYPE_ENTERPRISE = "Enterprise";
	@Autowired
	private AddEnterpriseMapper addEnterpriseMapper;

	@Override
	public String addNewEnterprise(EnterpriseInformation enterpriseInformation) {
		String enterpriseId = new CreateId().createId(IDTYPE_ENTERPRISE);
		Date registerDate=DateUtil.getRegisterDate();
		enterpriseInformation.setEnterpriseId(enterpriseId);
		enterpriseInformation.setRegisterDate(registerDate);
		int repeatEnterpriseCount=addEnterpriseMapper.getRepeatEnterpriseCount(enterpriseInformation.getEnterpriseName(),
				enterpriseInformation.getCardType(), enterpriseInformation.getCardId());//查询重复企业信息数量
		System.out.println(repeatEnterpriseCount);
		String addMessage = "";
		if(repeatEnterpriseCount==0) {//判断插入的内容是否重复
			int isSuccess = addEnterpriseMapper.addNewEnterprise(enterpriseInformation);
			
			if (isSuccess == 1) {//是否插入成功
				addMessage = enterpriseId;
			}else {
				addMessage="error";
			}
		}else {
			addMessage="enterprise repeat";
		}
		// TODO Auto-generated method stub
		return addMessage;
	}

}
